package il.ac.tau.cvws.scrabblesidekick.server.util.math;

import il.ac.tau.cvws.scrabblesidekick.shared.util.math.Point;

import java.util.Collection;

public class MathUtil
{
	public static double getMaxDistance(Collection<Point> pointSet)
	{
		double maxDist = 0;
		
		for (Point p1 : pointSet)
		{
			for (Point p2 : pointSet)
			{
				double currDist = p1.dist(p2);
				
				if (currDist > maxDist)
				{
					maxDist = currDist;
				}
			}
		}
		
		return maxDist;
	}
	
	public static Point getMidPoint(Collection<Point> points)
	{
		Point resPoint = new Point(0.0, 0.0, 0.0);
		int num = 0;
		
		for (Point p : points)
		{
			num++;
			
			resPoint.setX(resPoint.getX() + p.getX());
			resPoint.setY(resPoint.getY() + p.getY());
			resPoint.setZ(resPoint.getZ() + p.getZ());
		}
		
		resPoint.setX(resPoint.getX() / num);
		resPoint.setY(resPoint.getY() / num);
		resPoint.setZ(resPoint.getZ() / num);
		
		return resPoint;
	}
}
